import React, { Component } from 'react'
import { Carousel } from 'antd-mobile'
import { connect } from 'react-redux'
import uuid from 'uuid/v4'
import reduxPage from '@reduxPage'
import { getHome } from '@actions'
import { imgUrl, http, setShare } from '@utils'
import {
  ErrorFetch,
  Layout,
  Nav,
  Btn,
  WrapLink,
  HomeMessage,
  HomeLimit,
  HomeLoanTypes,
  ProductList,
} from '@components'

const util = require('util')
@reduxPage
@connect(({ home }) => ({ home }))

export default class extends Component {
  static async getInitialProps(ctx) {
    // err req res pathname query asPath isServer
    const { store, isServer } = ctx
    console.log(`${isServer}-----------------------------`)
    console.log(store.getState().home)
    if (!store.getState().home) {
      try {
        const homeFetch = await http.get('/openapi/rest/v1/cn.meadin.open/mbi/mbi_type.get', null, isServer)
        const homeData = homeFetch.data
        console.log(homeFetch)
        store.dispatch(getHome(homeData))
      } catch (error) {
        const err = util.inspect(error)
        return { err }
      }
    }
    return null
  }
  state = {
    messageList: ['136****5422成功贷款2万元', '186****7399成功贷款3万元', '158****0919成功贷款5万元', '151****6655成功贷款3000元'],
  }
  componentDidMount() {
    // setShare({
    //   title: '嘟嘟e贷首页',
    //   desc: '一站式专业贷款服务平台',
    // })
  }
  render() {
    const { home, err } = this.props
    const { messageList } = this.state
    if (err) {
      return <ErrorFetch err={err} />
    }
    if (!home) return null
    return (
      <Layout title="首页">
        
      </Layout>
    )
  }
}
